Regexp - near and not linear

Hello, I am building a quick checker for bad words and I tried using regexp, but I have some problems.

I browsed through the forum looking for regexp, but either they are over my head or I could not find a solution.

In particular I have problem in discriminating words which have similar content.

E.g. if I try a regexp2 "([Nn])ear, DOORS will find wherever something containing near occurs, and will thus find linear, nearer, etc.

Is there a way to limit that only to Near/near by only using regexp2 or do I need to write a more complex code ?

Thanks in advance.

Bruno


Bruno Di Giandomenico - Thu Mar 17 15:51:31 EDT 2016

Re: Regexp - near and not linear
Mike.Scharnow - Thu Mar 17 18:35:12 EDT 2016

Hi Bruno,

In an ideal world with a complete support of all regular expressions, you could work with word boundaries (\b).

In DOORS you will have to think about alternatives.

Provided that the requirement's author used punctuation marks correctly, the word "near" will usually either be surrounded by blanks or it will be at the beginning of the string. It is rather rare that "near" is at the end of the sentence or directly before a comma or in quotation marks.

This means that you could use the following

Regexp re1 = regexp2 " [Nn]ear "
Regexp re2 = regexp2 "^[Nn]ear "

if (re1 mystring or re2 mystring) {
    ...
}

See also the post Re: Sentence in Object Text for more ideas.

Hope this helps,
Mike

Re: Regexp - near and not linear
Bruno Di Giandomenico - Fri Mar 18 03:01:48 EDT 2016

Mike.Scharnow - Thu Mar 17 18:35:12 EDT 2016

Hi Bruno,

In an ideal world with a complete support of all regular expressions, you could work with word boundaries (\b).

In DOORS you will have to think about alternatives.

Provided that the requirement's author used punctuation marks correctly, the word "near" will usually either be surrounded by blanks or it will be at the beginning of the string. It is rather rare that "near" is at the end of the sentence or directly before a comma or in quotation marks.

This means that you could use the following

Regexp re1 = regexp2 " [Nn]ear "
Regexp re2 = regexp2 "^[Nn]ear "

if (re1 mystring or re2 mystring) {
    ...
}

See also the post Re: Sentence in Object Text for more ideas.

Hope this helps,
Mike

I knew it was easy, I just could not see it.

Thanks really a lot.

 

Bruno